package com.ytjj.qmyx.supplychain.service;

import com.github.pagehelper.PageHelper;
import com.ytjj.qmyx.supplychain.common.api.CommonPage;
import com.ytjj.qmyx.supplychain.common.api.CommonResult;
import com.ytjj.qmyx.supplychain.common.model.response.SupplyChainBankerBrandRelationResponse;
import com.ytjj.qmyx.supplychain.mapper.SupplyChainBankerBrandRelationMapper;
import com.ytjj.qmyx.supplychain.mapper.entity.SupplyChainBankerBrandRelation;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class SupplyChainBankerBrandRelationService {

    @Resource
    private SupplyChainBankerBrandRelationMapper supplyChainBankerBrandRelationMapper;

    /**
     * 查询供应链品牌的可用供应商(已绑定关系)
     */
    public CommonPage<SupplyChainBankerBrandRelationResponse> findBankerAndBrandBySupplyChainBrandId(Integer id, Integer pageNum, Integer pageSize) {
//        List<SupplyChainBankerBrandRelationResponse> response = new ArrayList<>();
        PageHelper.startPage(pageNum, pageSize);
        List<SupplyChainBankerBrandRelationResponse> list = supplyChainBankerBrandRelationMapper.findSupplyBrandAndBankerRelation(id);

        return CommonPage.restPage(list);
    }

    public CommonResult addRelation(SupplyChainBankerBrandRelationResponse request) {
        SupplyChainBankerBrandRelation relation = new SupplyChainBankerBrandRelation();
        relation.setSupplyBrandId(relation.getSupplyBrandId());
        relation.setBankerId(request.getBankerId());
        relation.setBankerBrandId(request.getBankerBrandId());
        relation.setStatus(0);
        relation.setCreateTime(LocalDateTime.now());
        supplyChainBankerBrandRelationMapper.insertSelective(relation);
        return CommonResult.success();
    }

    public CommonResult deleteRelation(Integer id) {
        int i = supplyChainBankerBrandRelationMapper.deleteByPrimaryKey(id);
        if (i > 0) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    public CommonResult findSupplyBrandAndBankerBrandRelationScript() {

        return CommonResult.success();
    }
}
